﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Homework02
{
    public partial class Form1 : Form
    {
        int flag = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            timer1.Enabled = true;
            pictureBox1.Image = Homework02.Properties.Resources.潜艇左;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            timer1.Enabled = true;
            pictureBox1.Image = Homework02.Properties.Resources.潜艇右;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (flag == 0) 
            {
                this.pictureBox1.Left += 5;
                if (this.pictureBox1.Left > this.Width) 
                {
                    this.pictureBox1.Left = -this.pictureBox1.Width;
                }
            }
            else
            {
                this.pictureBox1.Left -= 5;
                if (this.pictureBox1.Left < -this.pictureBox1.Width)
                {
                    this.pictureBox1.Left = this.Width;
                }
            }
        }

        private void button2_MouseClick(object sender, MouseEventArgs e)
        {
            flag = 0;
        }

        private void button1_MouseClick(object sender, MouseEventArgs e)
        {
            flag = 1;
        }
    }
}
